// pages/appointment/index.js
import urls from '../../utils/urls.js'
import loginFn from '../../utils/login.js'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		details: false,
		statusNumber: '', //状态码
		tabitem: [{
				"id": 0,
				"text": '已预约',
				"status": 3
			},
			{
				"id": 1,
				"text": "已核销",
				"status": 4
			},
			{
				"id": 2,
				"text": "已过期",
				"status": 7
			},
		],
		tabIndex: 0,
		appointList1: [],
		appointList: [],
		container: 750,
		type: 'school'
	},
	showDetail: function(e) {
		console.log(e)
		console.log(e.currentTarget.dataset.index)
		// let index=e.currentTarget.dataset.index
		console.log(this.data.appointList[e.currentTarget.dataset.index])
		let appointList1 = this.data.appointList[e.currentTarget.dataset.index]
		console.log(appointList1)
		this.setData({
			details: !this.data.details,
			appointList1: appointList1
		})
	},
	setTab: function(e) {
		let status = e.currentTarget.dataset.status
		this.setData({
			tabIndex: e.currentTarget.dataset.index,
		})
		this.getappointList(status)
	},
	getappointList(e) {
		let that = this
		var appList = loginFn()
		// appList.isDebug = "1"
		if(this.data.type == 'school'){
			appList.schoolAdmin=1;
		}
		appList.status = e
		wx.request({
			url: urls.appList,
			data: appList,
			success: function(res) {
				console.log(res.data.data)
				that.setData({
					appointList: res.data.data
				})
			}
		})
	},
	getQrcode: function(options) {
		let that = this
		let qrCreate = loginFn()
		wx.request({
			url: urls.qrCreate,
			data: {
				page: 'pages/index/index',
				scene: 'appId_123',
				width: 280
			},
			method: 'GET',
			success: function(res) {
				console.log(res, 'code')
				res.data.data.file = urls.zhaopeixun + res.data.data.file
				that.setData({
					codeImg: res.data.data
				})
			},
			fail: function() {},
			complete: options.complete || function() {}
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		console.log('options:',options);
		if(options.type) {
			this.setData({
				type: options.type
			});
		}
		this.getappointList(3)
		this.getQrcode(options)
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
